/**
 * 數據解析類,解析從服務端接收到的數據
 * 
 * @author LuoDong
 * @email luo4521@online.net.tw
 * 2010-2-10 14:40
 */
package com.addcn.texas.utils
{
	import com.addcn.common.data.Global;
	
	public class  DataResolve
	{
		private static var _instance : DataResolve;	
		
		function DataResolve() : void
		{
			if ( _instance != null) {
				throw("[DataResolve]為單例類");
				return;
			}			
		}
		
		public static function getInstance() : DataResolve 
		{			
			if ( _instance == null) {				
				_instance = new DataResolve();
			}
			return _instance;
		}
		
		//解析玩家數據
		public function _resolveUser(r_data : Object) : Object		
		{			
			var _obj : Object = { };
			_obj["id"] 	  = r_data[0];
			_obj["name"]  = r_data[1];						
			_obj["photo"] = r_data[2];	
			_obj["gold"]  = r_data[3];
			_obj["level"] = r_data[4];	
			_obj["label"] = resolveUserLabel(r_data[5]);			
			_obj["sit"] = int(r_data[6]);
			_obj["chip"] = int(r_data[7]);			
			return _obj;			
		}
		
		//解析房間數據
		public function ResolveRoom(r_data : Object) : Object		
		{			
			/**
			 * 比赛场数据：
			 * 	  [ 0=>id, 1=>name, 2=>type, 3=>state, 4=>maxUser, 5=>maxSpec, 6=>uCount, 7=>speCount, 8=>isGame, 9=>isLimbo, 
			 * 		10=>race, 11=>cost, 12=>expend, 13=>buy, 14=>players 
			 *    ]
			 * 普通场数据：
			 * 	  [ 0=>id, 1=>name, 2=>type, 3=>state, 4=>maxUser, 5=>maxSpec, 6=>uCount, 7=>speCount, 8=>isGame, 9=>isLimbo, 
			 * 		10=>race, 11=>minBlind, 12=>maxBlind, 13=>minChip, 14=>maxChip
			 * 	  ]
			 */			
			var _obj : Object = { };
			_obj["id"] 		   = r_data[0];
			_obj["name"]       = r_data[1];
			_obj["type"]       = r_data[2];
			_obj["state"]      = r_data[3];			
			_obj["maxU"]       = r_data[4];
			_obj["maxS"]       = r_data[5];
			_obj["userCount"]  = r_data[6];
			_obj["sperCount"]  = r_data[7];
			_obj["game"]       = r_data[8];
			_obj["limbo"]      = r_data[9];
			_obj["race"]       = r_data[10];
			if (_obj["race"] == 0 ) { 
				//普通场				
				_obj["SmallBlind"] = r_data[11];
				_obj["BigBlind"]   = r_data[12];
				_obj["minChip"]    = r_data[13];
				_obj["maxChip"]    = r_data[14];					
			}else {
				//比赛场				
				_obj["cost"]    = r_data[11];
				_obj["expend"]  = r_data[12];
				_obj["buy"]     = r_data[13];
				_obj["players"] = r_data[14];
			}						
			return _obj;
		}
				
		
		//解析大厅类型数据
		public function ResolveHallType(r_data : Object) : Object
		{
			var _obj : Object = { };
			_obj["id"] 	  = r_data[0];
			_obj["name"]  = r_data[1];
			_obj["race"]  = r_data[2];
			return _obj;
		}
		
		//解析玩家進入的房間數據
		public function ResolveJoinRoom(r_data : Object) : Object
		{
			var _room : Object = {};			
			_room["id"] 		= r_data[0];
			_room["state"]      = r_data[1];
			_room["minBlind"]   = r_data[2];
			_room["maxBlind"]   = r_data[3];
			_room["minChip"]    = r_data[4];
			_room["maxChip"]    = r_data[5];
			return _room;
		}
		
		/**
		 * 解析房间中的玩家数据
		 * @param	r_data Object Array
		 * @return Object
		 */
		//public function ResolveRoomUser(r_data : Object) : Object
		//{
			//this._resolveUser(r_data);
			//
		//}
		
		//游戲數據解析
		public function _resolveGameInfo(r_data : Object) : Object		
		{			
			var _obj : Object = { };
			_obj["banker"] 		= r_data[0];
			_obj["index"]       = r_data[1];
			_obj["new"]       	= r_data[2];
			_obj["deals"]       = r_data[3];
			_obj["call"]  		= r_data[4];
			_obj["pot"]  		= r_data[5];
			_obj["indexArr"]    = r_data[6];
			_obj["pubPoker"]    = r_data[7];						   
			return _obj;
		}
		
		/**
		 * 解析扑克牌
		 * @param	r_data  Object 
		 * @return	Array   [ [牌型,花色],[牌型,花色],... ], 牌型范围为A-K, 花色范围为0-3，0为黑桃，1为红桃，2为梅花，3为方片
		 */
		public function resolvePoker(r_data : Object) : Array
		{	
			var _arr : Array = [];
			var _cards : Array = [];
			var _val : String;
			for each(_val in r_data) {				
				_arr =  _val.split(",");				
				_cards.push(_arr);				
			}
			return _cards;
		}
		
		public function resolveCall(r_type : *) : String
		{
			r_type = String(r_type);
			var _status : String;
			switch(r_type) {
					case '0':
						_status = "跟注";
						break;
					case '1':
						_status = "加注";
						break;
					case '2':
						_status = "棄牌";
						break;
					case '3':
						_status = "全下";
						break;	
					case '4':
						_status = "看牌";
						break;						
					default:
						_status = "";
						break;
			}
			return _status;
		}
		
		/**
		 * 解析玩家稱號
		 * @return String
		 */
		public function resolveUserLabel(r_label : int) : String
		{
			var _lable_list : Object = {			
						1:"新手試煉",
						2:"德州之門",
						3:"幸運之星",
						4:"狐朋狗友",
						5:"撲克粉絲",
						6:"直達牌桌",
						7:"魅力無限",
						8:"意思意思",
						9:"勇往直前",
						10:"號召好友",

						11:"散打高手",
						12:"兩個恰恰好",
						13:"雙喜臨門",
						14:"三人成行",
						15:"順水推舟",
						16:"五朵小花",
						17:"拜訪好友",
						18:"再接再勵",
						19:"成群結隊",
						20:"好手氣",

						21:"糊里葫蘆",
						22:"鐵支之友",
						23:"同花順來了",
						24:"感謝支持",
						25:"人多勢眾",
						26:"勝者為王",
						27:"高高手",
						28:"吃人夠夠",
						29:"唬人專家",
						30:"糊裡糊塗",

						31:"雙雙對對",
						32:"花團錦簇",
						33:"財源滾滾",
						34:"好友雲集",
						35:"揚揚得意",
						36:"誰人跟我比",
						37:"All In",
						38:"終場勝利",
						39:"擁抱勝利",
						40:"抗戰勝利",

						41:"錢員外",
						42:"世紀高手",
						43:"勝利女神",
						44:"不可思議",
						45:"賭王之王",
						46:"世界首富",
						47:"飄上雲端",
						48:"不可思議",
						50:"台灣傳奇",
						51:"傳奇戰神"
			}			
			return _lable_list[r_label];
		}
		
	}
	
}
